package com.yunzhong.appointment.essentialinformation.controller;

import com.github.pagehelper.PageInfo;
import com.yunzhong.appointment.base.RespData;
import com.yunzhong.appointment.entity.Bigthing;
import com.yunzhong.appointment.entity.Noticeboard;
import com.yunzhong.appointment.essentialinformation.service.INoticeService;
import com.yunzhong.appointment.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author 王仁海
 * @author ThinkPad
 * @desc 公告
 */
@Controller
@RequestMapping("baseinfo")
public class NoticeController {

    /**
     * 模型层接口
     */
    @Autowired
    private INoticeService noticeService;

    @RequestMapping("listAnnouncement")
    public String listBigthing(HttpServletRequest request, ModelMap mm) {
        //接收前台数据
        PageData pd = new PageData(request);
        //查询数据
        List<Noticeboard> varList = noticeService.queryNotice(pd);
        //得到分页数据
        PageInfo page = new PageInfo(varList);
        mm.put("page", page);
        mm.put("pd", pd);
        return "system/essentialinformation/announcement/listannouncement";
    }

    /**
     * @return
     * @desc 转到添加页面
     */
    @RequestMapping("addAnnouncement")
    public String addpage(){
        return "system/essentialinformation/announcement/addannouncement";
    }


    /**
     * 添加保存
     *
     * @return
     */
    @RequestMapping("saveAnnouncement")
    public String addsave(Noticeboard gg) {
        noticeService.save(gg);
        return "redirect:listAnnouncement";
    }

    /**
     * @param mp
     * @param id
     * @return
     * @desc 转到修改页面
     */
    @RequestMapping("editAnnouncement")
    public String editpage(ModelMap mp, String id,String pageNum) {
        Noticeboard byId = noticeService.queryById(id);
        mp.put("byId", byId);
        mp.put("pageNum", pageNum);
        return "system/essentialinformation/announcement/editannouncement";
    }

    /**
     * 修改保存
     *
     * @param gg
     * @return
     */
    @RequestMapping("editsaveAnnouncement")
    public String editsave(Noticeboard gg) {
        noticeService.edit(gg);
        return "redirect:listAnnouncement";
    }

    /**
     * @param ids 主键集合
     * @param ra
     * @return
     * @desc 删除
     */
    @RequestMapping("removeAnnouncement")
    public String delete(String[] ids, RedirectAttributes ra) {
        noticeService.delete(ids);
        return "redirect:listAnnouncement";
    }



}
